
<!-- Xu ly Click chon tu --> 
<script type="text/javascript" language="javascript">
    
    function CreateXMLHttpRequest()
    {
        if ( window.XMLHttpRequest )
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            return new XMLHttpRequest()
        }
        else if (window.ActiveXObject )
        {
            // code for IE6, IE5
            return new ActiveXObject("Microsoft.XMLHTTP")
        }
    }
    
    
    function ClickSkipListen(id)
    {
        var xmlHttp;
        xmlHttp = CreateXMLHttpRequest();
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var kq = xmlHttp.responseText;
			
                document.getElementById("contentListen").innerHTML = kq;
            }
        }
        
        var serverURL =  'ClickSkipListen?id='+id+'&t=' + (new Date()).getTime();
		
        xmlHttp.open("get", serverURL, true);
		
        xmlHttp.send(null);
    }
    
  
    function ClickNameListen(id)
    {
        var xmlHttp;
        xmlHttp = CreateXMLHttpRequest();
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var kq = xmlHttp.responseText;
			
                document.getElementById("contentListen").innerHTML = kq;
            }
        }
        
        var serverURL =  'ClickNameListen?id='+id+'&t=' + (new Date()).getTime();
		
        xmlHttp.open("get", serverURL, true);
		
        xmlHttp.send(null);
    }
    
    ///----------- Xu Ly Click View Transcript-------------///
    function ClickTranscript(id)
    {
        var xmlHttp;
        xmlHttp = CreateXMLHttpRequest();
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
            {
                var kq = xmlHttp.responseText;
			
                document.getElementById("ViewTranscript").innerHTML = kq;
            }
        }
        
        var serverURL =  'ClickTranscript?id='+id+'&t=' + (new Date()).getTime();
		
        xmlHttp.open("get", serverURL, true);
		
        xmlHttp.send(null);
    }
</script>

<?php
session_start();

function fixObject(&$object) {
    if (!is_object($object) && gettype($object) == 'object')
        return ($object = unserialize(serialize($object)));
    return $object;
}

$listListen = $_SESSION["listListen"];
$beginListen = new Listen();
$beginListen = $listListen[0];
$idBeginListen = $beginListen->ID;
$_SESSION["idBeginListen"] = $idBeginListen;

$temp = new Listen();

$question = new Question();
$listQuestionDefaut = $question->loadQuestionByListen($idBeginListen);
?>

<div class = "topic_video" id ="contentListen"> <!-- khung ghi đề bài -->
    <div id="NameListListen">
        <?php
        $numberObject = count($listListen);
        $_SESSION["numberObject"] = $numberObject;
        $nameTest = 0;
        $idListenCurrent = $_SESSION["idListenCurrent"];
        for ($i = $idBeginListen; $i < $numberObject + $idBeginListen; $i++) {
            $nameTest++;
            ?>
            <a href="#"   onclick='ClickNameListen(<?php echo $i; ?>);'
            <?php
            if ($idListenCurrent == $i) {
                ?>           
                   style="color:red;"
                   <?php
               }
               ?>
               >Test <?php echo $nameTest; ?></a>
               <?php
           }
           ?>    
    </div> <!-- end namelistlisten -->



    <div class="left_video">
        <video width="320" height="240" controls="controls">
            <source src=" <?php echo (elgg_get_site_url() . $temp->Video) ?>" type="video/mp4"/>
        </video>
        <br />
        <?php
        $idListenCurrent = $_SESSION["idListenCurrent"];
//        if ($idListenCurrent < $idBeginListen + $numberObject - 1) {
//            ++$idListenCurrent;
//        } else {
//            $idListenCurrent = $idBeginListen;
//        }
        ?>
        
        <p >View Transcript: 
            <a href="#" onclick='ClickTranscript(<?php echo $idListenCurrent; ?>);'>English</a>
        </p>
        <div id="ViewTranscript"> </div>
    </div>

    <div class="right_video"> <!-- Phần Câu Trả Lời -->
        <?php
        if (session_is_registered("listQuestionUser")) {    //load khi an nut check answers
            $listQuestionDefaut = $_SESSION['listQuestionUser'];    //Lay lai các cau hoi da duoc check
            unset($_SESSION['listQuestionUser']);
        }

        for ($i = 0; $i < count($listQuestionDefaut); $i++) {
            $tempQuestion = new Question();
            $tempQuestion = $listQuestionDefaut[$i];
            ?>
            <div id="prompt_text" >

                <div id="question" class="recording-complete">
                    <p>
                        <span class="prompt-number"><?php echo $i + 1; ?></span> 
                        <span class="prompt-content"><?php echo $tempQuestion->Title; ?></span>
                    </p>
                </div>

                <div class="input">  
                    <div class="options" align="left" style="margin-left:30px;">
    <?php
    $myArrayAnswer = array(
        $tempQuestion->Answer1 => '2',
        $tempQuestion->Answer2 => '3',
        $tempQuestion->Answer3 => '1');

 //   $myRealArrayAnser = array();
    
   // $myRealArrayAnser = array_rand($myArrayAnswer,3);
//    for ($i = 0; $i < 3; ++$i) {
//        $rand = array_rand($myArrayAnswer, 3);
//        unset($myArrayAnswer[$rand]);
//        foreach ($myArrayAnswer as $myTempQuestion) {
//            if ($rand == (int) $myTempQuestion) {
//                $myRealArrayAnser[] = $myTempQuestion;
//            }
//        }
//    }

    echo elgg_view('input/radio', array('name' => $tempQuestion->ID,
        'isCheck' => $_SESSION['isCheck'],
        'userCheck' => $tempQuestion->Right_Answer,
        'value' => $tempQuestion->User_Answer, 'options' => $myArrayAnswer
    ));
    ?>
                    </div>
                </div>
            </div>
<?php
}
unset($_SESSION['isCheck']);
?>
        <br />
        
       
        <input style="float:right" type="submit" name="check_answers" value="Check answers" class="elgg-button elgg-button-submit"/>
        <a style="float:right" href="#" onclick='ClickSkipListen(<?php echo $idListenCurrent; ?>);'>Next </a>
    </div><!-- End Phần Câu Trả Lời -->
</div> <!-- End khung ghi đề bài -->